﻿using System;
using System.Windows.Forms;
using Microsoft.WowAddonStudio.FrameXml.Design;
using Microsoft.WowAddonStudio.FrameXml.Designer.Properties;

namespace Microsoft.WowAddonStudio.FrameXml.Designer
{
    public partial class FrameXmlDesignerForm : Form
    {
        private FrameXmlDesignerFactory designerFactory;

        public FrameXmlDesignerForm()
        {
            InitializeComponent();
            InitializeDesignerFactory();
        }

        private void InitializeDesignerFactory()
        {
            designerFactory = new FrameXmlDesignerFactory { WowBasePath = Settings.Default.WowBasePath };
        }

        public TService GetService<TService>()
        {
            return (TService)GetService(typeof(TService));
        }

        protected override object GetService(Type service)
        {
            if (service == typeof(FrameXmlDesignerFactory))
                return designerFactory;

            return base.GetService(service);
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            var frameXmlForm = new FrameXmlForm { MdiParent = this };
            frameXmlForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
                                     {
                                         Filter = "FrameXML Files (*.xml)|*.xml|All Files (*.*)|*.*"
                                     };

            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                var frameXmlForm = new FrameXmlForm(openFileDialog.FileName) { MdiParent = this };
                frameXmlForm.Show();
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog
                                                {
                                                    Filter = "FrameXML Files (*.xml)|*.txt|All Files (*.*)|*.*"
                                                };

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                var fileName = saveFileDialog.FileName;
                var frameXmlForm = (FrameXmlForm)this.ActiveMdiChild;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
                childForm.Close();
        }
    }
}
